package com.nantai.jiafang.nantaijiafang.activity.login;

import android.content.Context;
import android.content.SharedPreferences;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by Administrator on 2017/10/12.
 */

public class SjieTools {
    public static void savepassword(Context context,String filename,boolean remember,Remember account){
        SharedPreferences.Editor editor = context.getSharedPreferences(filename, MODE_PRIVATE).edit();
        if (remember) {
            editor.putString("account", account.getAccount());
            editor.putString("password", account.getPassword());
            editor.putBoolean("remember", account.isRemember());
            editor.putString("name", account.getName());
            editor.commit();
        }else {
            editor.putString("account", "");
            editor.putString("password", "");
            editor.putBoolean("remember", false);
            editor.putString("name", account.getName());
            editor.commit();
        }
    }
    public static Remember readpassword(Context context,String filename){
        SharedPreferences pref = context.getSharedPreferences(filename,
                MODE_PRIVATE);
        Remember remember=new Remember();
        remember.setAccount(pref.getString("account", ""));
        remember.setPassword(pref.getString("password", ""));
        remember.setRemember(pref.getBoolean("remember", false));
        remember.setName(pref.getString("name","南泰"));
        return remember;
    }
}
